import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_flame/bloc/game_bloc/GameBloc.dart';
import 'package:flutter_flame/routes/RouteGame.dart';
import 'package:window_manager/window_manager.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // 直接用try，如果出错，一般是该平台不支持也不需要设置
  try {
    // 横屏
    await SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
    // 状态栏自动收起模式
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);

    // 窗口设置
    await windowManager.ensureInitialized();
    WindowOptions windowOptions = WindowOptions(
      // size: Size(GameConfig.gameScreenWidth, GameConfig.gameScreenHeight),
      maximumSize: Size.infinite,
      minimumSize: Size(400, 300),
      // center: true,
      backgroundColor: Colors.transparent,
      skipTaskbar: false,
      // 在任务栏隐藏
      titleBarStyle: TitleBarStyle.normal,
      // TitleBarStyle.hidden是隐藏标题栏
      title: '植物大战僵尸',
    );
    windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show();
      await windowManager.focus();
    });
  } catch (_) {}

  final gameBloc = GameBloc();
  runApp(GameWidget(game: RouterGame(gameBloc)));
}
